require 'rubygems'
require 'nokogiri'
require 'open-uri'

def main
    raise ArgumentError, 'Input a valid url!' if ARGV.empty?
    url = ARGV[0]
    path = File.expand_path('../download', __FILE__)
    Dir.mkdir(path) if !File.exists?(path)
    download(path, url)
end

def download(path, url)
    @dom = Nokogiri::HTML(open(url))
    @dom.css('div#eData > dl > dd:eq(1)').each do |item| 
        image = /[\w_]+\.(jpg|jpeg|png)/i.match(item.inner_text).to_s
        stream = open(item.inner_text, 'rb') { |f| f.read }
        open(File.join(path, image), 'wb') { |f| f.write(stream) }
    end
end

if __FILE__ == $0
    begin
        main
    rescue Exception => e
        puts e.message, e.backtrace
    end
end